var _nas = _nas || {};
_nas.loadJs = function(url, params) {
    var query = _nas.getQuery(params);
    var ts = document.createElement("img");
    var s = document.getElementsByTagName("body")[0]; 
    ts.src = url + "?" + query;
    ts.onerror = function () {
        ts.src = 'http://track.aiskater.com' + "?" + query;
        ts.onerror = null;
    }
    s.parentNode.appendChild(ts);
}
_nas.getQuery = function(params) {
    var relustAry = [];
    params['referer'] = encodeURIComponent(document.referrer);
    params['color'] = screen['colorDepth'];
    params['resolution'] = screen['width']+'x'+screen['height'];
    params['flash'] = _nas.flashChecker();
    params['flash'] = params['flash']['v'];
    params['java'] = navigator.javaEnabled();
    for(var i in params){
        relustAry.push(i+'='+params[i]);
    }
    this.baiduSearch();
    return relustAry.join('&');
}
_nas.nasLoad = function(host, params) {
    _nas.loadJs(host + "/", params)
}
_nas.flashChecker = function () {
    var hasFlash = 0;
    var flashVersion = 0;
    if (document.all) {
        var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
        if (swf) {
            hasFlash = 1;
            VSwf = swf.GetVariable("$version");
            flashVersion = parseInt(VSwf.split(" ")[1].split(",")[0]);
        }
    } else {
        if (navigator.plugins && navigator.plugins.length > 0) {
            var swf = navigator.plugins["Shockwave Flash"];
            if (swf) {
                hasFlash = 1;
                var words = swf.description.split(" ");
                for (var i = 0; i < words.length; ++i) {
                    if (isNaN(parseInt(words[i]))) continue;
                    flashVersion = parseInt(words[i]);
                }
            }
        }
    }
    return {
        f: hasFlash,
        v: flashVersion
    };
}
var _hmt = _hmt || [];
_nas.baiduSearch = function () {
    if(!/www\.baidu\.com\/link\?url/.test(document.referrer)){
        return;
    }
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?dc862b8e426ccf00969290444f2edb4b";
      var s = document.getElementsByTagName("script")[0]; 
      s.parentNode.insertBefore(hm, s);
    })();
}